//导入封装后的axios
import request from "@/utils/request";

//定义登录接口
export interface LoginDTO{
  account: string; //用户名
  password: string; //密码
}
// 定义登录响应数据类型
export interface LoginResponseData {
  accessToken: string;
  userInfo: {
    id: number; //用户id
    account: string; //用户名
  };
  tokenType: string; //令牌类型
}

//注册接口
export interface RegisterDTO{
  account: string; //用户名
  password: string; //密码
  phone: string; //手机号
}

//验证码登录接口
export interface VerifyCodeLoginDTO{
  phone: string; //手机号
  code: string; //验证码
}



//登录作品api
export const AuthApi = {
  //登录
  accountLogin:async (data:LoginDTO)=>{
    return await request.post<LoginResponseData>('/users/accountLogin',data)
  },

  //注册
  register:async(data:RegisterDTO)=>{
    return await request.post('/users/register',data)
  },

  //获取验证码
  getVerifyCode:async(phone:string)=>{
    return await request.post(`/users/getCode`,{phone})
  },
  //验证码登录
  verifyCodeLogin:async(data:VerifyCodeLoginDTO)=>{
    return await request.post<LoginResponseData>('/users/verifyCodeLogin',data)
  },
  // 退出登录
  logout:async(accessToken:string)=>{
    return await request.post('/users/logout',{accessToken})
  }
}